import router from "@/router"
import { useUserStore } from "@/store/user"

export function logout(before?: () => void, after?: () => void) {
    const store = useUserStore()
    before && before()
    // token 过期  让用户重新登录 和退出登录的逻辑一样
    // 清除token
    localStorage.removeItem('token')
    // 清空路由
    store.routers.forEach(item => router.removeRoute(item.name))
    // 清除pinia
    store.username = ''
    store.menus = []
    // 跳转到login
    router.push("/login")
    // 调用callback
    after && after()
}